	import {
		getVoById
	} from '@/apis/bill/label-stock.js'

	import {
		getLabelStockProgressByBillDetailId
	} from '@/apis/bill/purchase-reserve-label.js'

	import {
		getDefaultDataConnPermissions
	} from '@/apis/bsd/store.js'

	/**	
	 * 处理手动录入初始化
	 */
	export const initManualData = function() {
		// init 仓库
		// getDefaultDataConnPermissions().then(res => {
		// 	if (!res.data.flag) return
		// 	const data = res.data.data || {}
		// 	this.$set(this.labelData, 'storeId', data.id)
		// 	this.$set(this.labelData, 'storeName', data.name)
		// })
	}

	/**
	 * 从其他列表带来的，单据明细行
	 */
	export const initFromBillData = function() {
		const data = this.$getPageParams('detail')
		if (data) {
			const row = data.row || {}
			const billData = data.billData || {}
			// 赋值
			this.labelData = row
			const billDetailId = row.id
			this.$set(this.labelData, 'billDetailId', billDetailId)
			this.$set(this.labelData, 'quantity', 0)
			this.$set(this.labelData, 'billId', billData.id)
			this.$set(this.labelData, 'billNo', billData.billNo)
			this.$set(this.labelData, 'billType', "purchaseReserve")
			this.$set(this.labelData, 'billBusinessTime', billData.businessTime)

			// 查询明细的进度
			getLabelStockProgressByBillDetailId(billDetailId).then(res => {
				if (!res.data.flag) return
				this.piecesCountProgress = res.data.data || {}
			})
		}
	}

	/**
	 * 编辑单据
	 */
	export const initUpdateData = function(id) {
		uni.showLoading()
		getVoById(id).then(res => {
			if (!res.data.flag) return
			const data = res.data.data || {}
			this.labelData = data
		}).finally(_ => {
			uni.hideLoading()
		})
	}